package com.yunxin.core.infra.persistence.repository.channel;

import com.yunxin.core.domain.model.channel.ChannelType;
import com.yunxin.core.domain.model.channel.ChannelTypeRepository;
import com.yunxin.core.infra.persistence.converter.ChannelConvertor;
import com.yunxin.core.infra.persistence.entity.channel.ChannelTypeDO;
import com.yunxin.core.infra.persistence.mapper.channel.ChannelTypeExtendMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

/**
 * @author zero°
 * @since 2023-07-12
 */
@Repository
@RequiredArgsConstructor
public class ChannelTypeRepositoryImpl implements ChannelTypeRepository {

    private final ChannelTypeExtendMapper channelTypeExtendMapper;

    private final ChannelConvertor channelConvertor;
    @Override
    public boolean saveChannelType(ChannelType channelType) {
        ChannelTypeDO channelTypeDO = channelConvertor.formChannelType(channelType);
        int count = channelTypeExtendMapper.insertSelective(channelTypeDO);
        return count > 0;
    }

    @Override
    public boolean updateChannelType(ChannelType channelType) {
        ChannelTypeDO channelTypeDO = channelConvertor.formChannelType(channelType);
        int count = channelTypeExtendMapper.updateByPrimaryKeySelective(channelTypeDO);
        return count > 0;
    }

    @Override
    public ChannelType getChannelTypeById(Long id) {
        ChannelTypeDO channelTypeDO = channelTypeExtendMapper.selectByPrimaryKey(id);
        return channelConvertor.toChannelType(channelTypeDO);
    }
}
